﻿using DreamWork.Configuration;
using System;
using System.Globalization;

namespace System
{
    public static class ControllerExtensions
    {
        public static string FormatDateTimeToJson(this DateTime thisValue)
        {
            if (thisValue == null)
            {
                return string.Empty;
            }
            return FormattableString.Invariant($"{thisValue:yyyy-MM-dd HH:mm}");
        }

        public static DateTime? FormatDateTimeToShangHaiZoneDateTime(this DateTime thisValue)
        {
            if (thisValue == null)
            {
                return null;
            }
            return thisValue.ToUniversalTime().AddHours(8);
        }
        public static DateTime? FormatDateTimeOffsetToDateTime(this DateTimeOffset thisValue)
        {
            if (thisValue == null)
            {
                return null;
            }
            ///TODO 这些时间用的时候应该要理解是什么意思
            return thisValue.ToUniversalTime().DateTime.AddHours(8);
        }
        public static bool ContainsEx(this string thisValue, string searchValue)
        {
            if (string.IsNullOrEmpty(thisValue) && string.IsNullOrEmpty(searchValue))
            {
                return true;
            }
            return thisValue?.ToUpper(CultureInfo.InvariantCulture).Contains(searchValue?.Trim().ToUpper(CultureInfo.InvariantCulture)) ?? false;
        }
    }
}
